package com.hu.common.util.adm;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * @author 355760
 * @ClassName ServletHelper
 * @Description servlet请求上下文工具类
 */
public class ServletHelper {

    public static HttpServletRequest getServletRequest() {
        return ((ServletRequestAttributes) Objects.requireNonNull(
                RequestContextHolder.getRequestAttributes())).getRequest();
    }

    public static String getHeader(String headerName) {
        final HttpServletRequest servletRequest = getServletRequest();
        return servletRequest.getHeader(headerName);
    }
}
